let express = require('express');
require('express-group-routes'); //这个直接在express上修改, 因此不需要let xx = yy;
let router = express.Router();
let eventproxy = require('eventproxy');

let MerchantApi = require('../api/MerchantApi');
let GoodsApi = require('../api/GoodsApi');
let OrderApi = require('../api/OrderApi');

router.group('/MerchantApi', function (router) {
  // router.get('/group-test', function (req, res, next) {
  //   console.log(req.session);
  //   res.send('route group test');
  // });
  // router.get('/pagination', function (req, res) {
  //   async.series([
  //     function (callback) {
  //       knex('tb_merchant').where('is_deleted', 1).update('is_deleted',  0).then(function (result) {
  //         callback(null, result);
  //       });
  //     },
  //     function (callback) {
  //       knex('tb_merchant').orderBy('id').where('is_deleted', 1).paginate().then(function (data) {
  //         callback(null, data);
  //       });
  //     },
  //     function (callback) {
  //       knex('tb_merchant').orderBy('id').where('is_deleted', 0).paginate().then(function (data) {
  //         callback(null, data);
  //       })
  //     }
  //     ], (error, result)=>{
  //       res.send(result);
  //   });
  // });
  router.post('/test', function (req, res) {
    console.log(req.session);
    console.log(req._params);
    res.json(req._params);
  });

  router.post('/login', MerchantApi.login);
  router.post('/register', MerchantApi.register);
  router.post('/resetPassword', MerchantApi.resetPassword);
  router.post('/verifyInfo', MerchantApi.verifyInfo);
  router.get('/registerSms', MerchantApi.registerSms);
  router.get('/resetPasswordSms', MerchantApi.resetPasswordSms);
  router.get('/addressList', MerchantApi.addressList);
  router.post('/addAddress', MerchantApi.addAddress);
  router.post('/updateAddress', MerchantApi.updateAddress);
  router.get('/deleteAddress', MerchantApi.deleteAddress);
  router.get('/userInfo', MerchantApi.userInfo);
  router.post('/updateUserInfo', MerchantApi.updateUserInfo);
  router.get('/aboutShells', MerchantApi.aboutShells);
});

router.group('/GoodsApi', function (router) {
  router.get('/category', GoodsApi.category);
  //router.get('/subCategory', GoodsApi.subCategory);
  router.get('/goodsList', GoodsApi.goodsList);
  router.get('/goodsInfo', GoodsApi.goodsInfo);
  router.get('/goodsDetail', GoodsApi.goodsDetail);
});

router.group('/OrderApi', function (router) {
  router.post('/addOrder', OrderApi.addOrder);
  router.post('/deleteOrder', OrderApi.deleteOrder);
  router.post('/updateOrder', OrderApi.updateOrder);
  router.get('/historyPayerPhone', OrderApi.historyPayerPhone);
  router.get('/orderList', OrderApi.orderList);
  router.get('/orderInfo', OrderApi.orderInfo);
  router.get('/goodsInfo', OrderApi.goodsInfo);
  router.post('/rejectPay', OrderApi.rejectPay);
  router.get('/lastAddress', OrderApi.lastAddress);
  router.get('/payOrder', OrderApi.payOrder);
});

exports = module.exports = router;
